package servlet;

import hbase.Student;

import hbase.HbaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * @author Judy
 * @data 2022/3/12 16:17
 */
@WebServlet("/studentAdd")
public class HbaseAdd extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String studentId = req.getParameter("studentId");
        String name = req.getParameter("name");
        String date = req.getParameter("date");
        String number = req.getParameter("number");
        String semester = req.getParameter("semester");
        String studentStatus = req.getParameter("studentStatus");

//        List<String> obj_value = (new UserLogFromHBase()).getUserLogList("Student", new String[]{"StuInfo","Grades",});

        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student = new Student();
        student.setStudentId(studentId);
        student.setName(name);
        student.setDate(date);
        student.setNumber(number);
        student.setSemester(semester);
        student.setStudentStatus(studentStatus);
        studentArrayList.add(student);


        HbaseUtil hbaseAddUtil = new HbaseUtil();
        String obj_value = "";
        try {
            obj_value = hbaseAddUtil.insertinfo("niit01","2181","bigdata",studentArrayList);
        } catch (Exception e){
            e.printStackTrace();
        }

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>"+  obj_value);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}

